<div class="m-2">
    <i class="fa fa-podcast mr-1"></i><label class="title">系统公告</label>
    <hr class="mt-0">

    <form id="form-broadcast">
        <div class="form-group">
            <textarea id="content" name="content" data-provide="markdown" rows="12" data-savable="false" data-iconlibrary="fa"></textarea>
        </div>

        <div class="mt-4">
            <button id="btn-send" type="button" class="btn btn-primary">确认发布</button>
        </div>
    </form>
</div>

<script src="/www/js/bootstrap.notify.min.js"></script>
<script>
$('#form-broadcast #content').markdown();
$('#btn-send').click(function() {
    var text = $('#form-broadcast #content').val();
    if (!text || text.length <= 0) {
        $.notify({ message: '公告内容不能空', icon: 'fa fa-exclamation-circle', title: '发送失败' }, { type: 'danger', delay: 500 });
        return;
    }

    var args = new FormData();
    args.append('content', marked('<i class="fa fa-bullhorn mr-1"></i><b class="mr-2">系统公告:</b>' + text));

    $.ajax({
        url: '/dashboard/admin/broadcast',
        type: 'POST',
        data: args,
        dataType: 'json',
        processData: false,
        contentType: false,
        cache: false,
        success: function(rsp) {
            if (rsp.ok) {
                $.notify({ message: '发送成功', icon: 'fa fa-comment'}, { type: 'success', delay: 500 }); 
            } else {
                $.notify({ message: rsp.err_msg, icon: 'fa fa-exclamation-circle', title: '发送失败' }, { type: 'danger', delay: 500 }); 
            }
        }
    });
});
</script>